package com.cf.r1032_ak;

import java.io.*;
import java.util.Arrays;

public class e {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int t = Integer.parseInt(br.readLine());
        while (t-- > 0) {
            solve();
        }
        out.flush();
        out.close();
        br.close();
    }

    static void solve() throws IOException {
        String[] s = br.readLine().split(" ");
        char[] l = s[0].toCharArray();
        char[] r = s[1].toCharArray();
        int n = l.length;
        if (Arrays.equals(l, r)) {
            out.println(n * 2);
            return;
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (l[i] == r[i]) {
                ans += 2;
            } else if (r[i] - l[i] >= 2) {
                out.println(ans);
                return;
            } else {
                ans++;
                for (int j = i + 1; j < n; j++) {
                    if (l[j] == '9' && r[j] == '0') {
                        ans++;
                    } else {
                        out.println(ans);
                        return;
                    }
                }
                break;
            }
        }
        out.println(ans);

    }
}
